package com.loe.test

import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import com.binioter.guideview.Component
import com.binioter.guideview.Guide
import com.binioter.guideview.GuideBuilder
import com.loe.mvp.ext_java.safe
import kotlinx.android.synthetic.main.layout_guide1.view.*

fun View.showGuide(onNext: () -> Unit): Guide
{
    var guide: Guide? = null

    val builder = GuideBuilder()
        .setTargetView(this)
        .setAlpha(150)
        .setHighTargetCorner(20)
        .setHighTargetPadding(10)
        .setAutoDismiss(false)
//    builder.setOnVisibilityChangedListener(object : GuideBuilder.OnVisibilityChangedListener
//    {
//        override fun onShown()
//        {
//        }
//
//        override fun onDismiss()
//        {
//
//        }
//    })
    builder.addComponent(object : Component
    {
        override fun getView(inflater: LayoutInflater): View
        {
            val layout = inflater.inflate(R.layout.layout_guide1, null)
            layout.buttonNext.setOnClickListener()
            {
                guide?.dismiss()
                onNext()
            }
            return layout
        }

        override fun getAnchor(): Int = Component.ANCHOR_BOTTOM

        override fun getFitPosition(): Int = Component.FIT_START

        override fun getXOffset(): Int = 0

        override fun getYOffset(): Int = 15
    })
    guide = builder.createGuide()
    safe()
    {
        guide.show(context as Activity)
    }
    return guide
}